#include "gtest/gtest.h"
#include "ArrayList.h"

static boolean enumArrayTestCallback(ArrayList* list, void* data, void* userData) {
    return TRUE;
}

TEST(ArrayListTest, arrayListAddTest) {
    ArrayList*  list = newArrayList();
    int a = 1;
    arrayListAdd(list, (void*)&a);
    int* b = (int*)arrayListGet(list, 0);
    ASSERT_EQ(a, *b);
    deleteArrayList(list);
}

TEST(ArrayListTest, arrayListSizeTest) {
    ArrayList*  list = newArrayList();
    int a = 1;
    int b = 2;
    arrayListAdd(list, (void*)&a);
    arrayListAdd(list, (void*)&b);
    ASSERT_EQ(arrayListSize(list), 2);
    deleteArrayList(list);
}

TEST(ArrayListTest, arrayListAddKeyDataTest) {
    ArrayList*  list = newArrayList();
    int a = 1;
    int b = 2;
    arrayListAdd(list, (void*)&a);
    arrayListAddKeyData(list, 0, (void*)&b, sizeof(b));
    int* c = (int*)arrayListGetKeyData(list, 0);
    ASSERT_EQ(b, *c);
    c = (int*)arrayListGet(list, 0);
    ASSERT_EQ(a, *c);
    deleteArrayList(list);
}

TEST(ArrayListTest, arrayListEnumTest) {
    ArrayList*  list = newArrayList();
    int a = 1;
    int b = 2;
    arrayListAdd(list, (void*)&a);
    arrayListAdd(list, (void*)&b);
    arrayListEnum(list, enumArrayTestCallback, NULL);
    deleteArrayList(list);
}

TEST(ArrayListTest, arrayListClearTest) {
    ArrayList*  list = newArrayList();
    int a = 1;
    int b = 2;
    arrayListAdd(list, (void*)&a);
    arrayListAdd(list, (void*)&b);
    arrayListClear(list);
    ASSERT_EQ(arrayListGet(list, 0), (void*)NULL);
    ASSERT_EQ(arrayListSize(list), 0);
    deleteArrayList(list);
}

TEST(ArrayListTest, arrayListRemoveAllTest) {
    ArrayList*  list = newArrayList();
    int a = 1;
    int b = 2;
    arrayListAdd(list, (void*)&a);
    arrayListAdd(list, (void*)&b);
    arrayListRemoveAll(list, NULL);
    ASSERT_EQ(arrayListGet(list, 0), (void*)NULL);
    ASSERT_EQ(arrayListSize(list), 0);
    deleteArrayList(list);
}


